const videoDao = require('../dao/videoDao')
const jwt = require('jsonwebtoken')
const config = require('../config/config.js')

// 发布视频
exports.post = async ctx => {
  let body = ctx.request.body
  let token = ctx.request.headers["authorization"];
  let payload = jwt.verify(token,config.security.secretKey)
  body.author = payload.username
  body.status = 0
  let res = await videoDao.create(body)
  ctx.success('发表成功')
}

// 删除某条数据
exports.delVideo = async ctx => {
  let { id } = ctx.request.query
  const res = await videoDao.delById(id);
  ctx.success('删除成功')
}

// 审核通过
exports.passVideo = async ctx => {
  let { id } = ctx.request.query
  const res = await videoDao.pass(id);
  ctx.success('审核通过')
}

// 获取全部
exports.getAllVideo = async ctx => {
  let { p = 1,limit = 999 } = ctx.request.query
  let offset = (p - 1) * limit;
  let body = {
    offset:offset,
    limit:Number(limit)
  }
  const res = await videoDao.findAll(body);
  ctx.success('',res)
}

exports.getAll = async ctx => {
  let body = ctx.request.body
  let res = await videoDao.findAll(body)
  ctx.success('',res)
}